package Akanksha;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * Simple Basal Profile Class
 * @author Stephen
 */
public class BasalProfile {
    
    // saves all the basal profiles created in an arraylist
    public static int[][] basal = new int[10][24];
    // saves all the basal profiles created in an arraylist
     public static ArrayList<String> basalProfileNameArray = new ArrayList<String>();
    // saves basal profile as an array
    public double[] profile = new double[24];
    // saves basal profile name as string
    private String profileName = new String(); 
    // saves whether a profile is active or not
    private boolean active ;
    //Used to save profile name
    public void saveBasalProfileName(String name){
                profileName = name;
                //adds the profile name to basalProfileNameArray array
                basalProfileNameArray.add(profileName);

    }
    // Used to save the profile
    public void saveBasalProfile(int[] basalProfile){
        
        int basalArrayLength = basal.length;
        for(int i =0; i <= basalProfile.length ; i++)
        {
            this.profile[i] = basalProfile[i];
            basal[basalArrayLength][i] = basalProfile[i];
        }
        
        // adds the basal profile to the basal array
        
        
    }
    ///Used to save the basal profile
    public void saveProfile() {
        try {
//            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("BasalProfiles.txt", true))); //append to file
            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("BasalProfiles.txt", false))); //overwrite file
            for(int iter = 0; iter < 24; iter++)
            {
                out.println( profile[iter] );                
            }
            out.close();
        } catch (IOException e) {
            System.out.println("ERROR:  Exception:  " + e.toString());
        }
    }
    
    public void display() {
        for(int iter = 0; iter < 24; iter++) {
            System.out.println("Hour:\t" + iter + "\tRate:\t" + profile[iter]);
        }
    }
    
    public static void activate(String profileName){
        int j =0;
        for(;j<= basalProfileNameArray.size();j++)
        {
            if(basalProfileNameArray.get(j).equalsIgnoreCase(profileName))
            {
                break;
            }
            else
            {
                j++;
            }      
        }
        
        int currentHour = Clock.GetCurrentHour(); 
        
        //InsulinSensor insulinSensor = new InsulinSensor();
      //  insulinSensor.startInsulinBasalProfile(basal[j][24],currentHour);
       
    }
    ///Used for testing this class
//    public static void main (String args[]) {
//         BasalProfile myProfile = new BasalProfile();
//         for(int iter = 0; iter < 24; iter++)
//         {
//             myProfile.profile[iter] = iter + 1;
//         }
//         myProfile.saveProfile();
//    }
}
